<?php
use yii\helpers\Url;
?>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>铝邦CRM客户管理系统</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="bootstrap/css/bootstrap-datetimepicker.min.css"/>
    <link rel="stylesheet" href="css/common.css"/>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/setting.css"/>
    <script src="js/jquery-1.12.3.min.js"></script>
    <script src="layui/layui.all.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <script src="bootstrap/js/bootstrap-datetimepicker.min.js"></script>
    <script src="bootstrap/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="js/commer.js"></script>
</head>
<body>
<div class="main-nav">
    <h3>企业</h3>
    <div class="all-client all-clues clues-on col-sm-1">全部企业</div>
    <div class="import-clues col-sm-1" data-toggle="modal" data-target="#importClient">导入企业</div>
    <div class="add-clues col-sm-1" data-toggle="modal" data-target="#addClient">+新增企业</div>
</div>
<!--搜索-->
<div class="clues-search">
    <label class="search-label label-left-lg">所在地区：</label>
    <select name="province" id="province" class="search-select">
        <option value="0">---省份---</option>
        <?php foreach($provinceList as $key=>$value){

        ?>
            <option value="<?=$value['code']?>"><?=$value['name']?></option>

        <?php
        }
        ?>
    </select>
    <select name="city" id="city" class="search-select">
        <option value="0">---城市---</option>
        <?php foreach($citiesList as $key=>$value){

            ?>
            <option value="<?=$value['code']?>"><?=$value['name']?></option>

            <?php
        }
        ?>
    </select>
    <label class="search-label label-left-sm">公司类型：</label>
    <select name="companyType" id="companyType" class="search-select">
        <option value="0">---请选择---</option>
        <?php foreach($companyCatsList as $key=>$value){

            ?>
            <option value="<?=$value['id']?>"><?=$value['name']?></option>

            <?php
        }
        ?>
    </select>
    <label class="search-label label-left-sm">客户等级：</label>
    <select name="customerLevel" id="customerLevel" class="search-select">
        <option value="0">---请选择---</option>
        <?php foreach($gradeList as $key=>$value){

            ?>
            <option value="<?=$value['id']?>"><?=$value['name']?></option>

            <?php
        }
        ?>
    </select>
    <label class="search-label label-left-sm">跟进状态：</label>
    <select name="followState" id="followState" class="search-select">
        <option value="0">---请选择---</option>
        <?php foreach($followStatusList as $key=>$value){

            ?>
            <option value="<?=$value['id']?>"><?=$value['name']?></option>

            <?php
        }
        ?>
    </select>
    <div class="clear"></div>
    <label class="search-label label-left-lg">未跟进时间：</label>
    <select name="unfollowTime" id="unfollowTime" class="search-select">
        <option value="0">---请选择---</option>
        <option value="1">1个月之内</option>
        <option value="2">2个月之内</option>
    </select>
    <label class="search-label label-left-sm">负责客服：</label>
    <select name="responService" id="responService" class="search-select">
        <option value="0">---部门---</option>
        <?php foreach($departmentsList as $value){

            ?>
            <option value="<?=$value['id']?>"><?=$value['departName']?></option>

            <?php foreach($value['twoGrade'] as $twoValue){
                ?>
                <option value="<?=$twoValue['id']?>">-<?=$twoValue['departName']?></option>
                <?php
                foreach($twoValue['threeGrade'] as $threeValue){
                    ?>
                    <option value="<?=$threeValue['id']?>">--<?=$threeValue['departName']?></option>
                    <?php
                    foreach($threeValue['fourGrade'] as $fourValue){
                        ?>
                        <option value="<?=$fourValue['id']?>">---<?=$fourValue['departName']?></option>
                        <?php
                        foreach($fourValue['fiveGrade'] as $fiveValue){

                            ?>

                            <option value="<?=$fiveValue['id']?>">----<?=$fiveValue['departName']?></option>
                        <?php } ?>
                        <?php
                    } ?>
                <?php    } ?>
            <?php } ?>

        <?php } ?>
    </select>
    <select name="serviceUser" id="serviceUser" class="search-select">
        <option value="0">---用户---</option>
    </select>
    <label class="search-label label-left-sm">指派状态：</label>
    <select name="appointState" id="appointState" class="search-select">
        <option value="0">---全部---</option>
        <option value="1">未指派</option>
        <option value="2">客服</option>
    </select>
    <div class="clear-many">清空</div>
</div>
<div class="clues-top-title">
    <p>已选<span class="chk-num">0</span>条线索</p>
    <div class="btn-comm btn-asg" data-toggle="modal" data-target="#appointClient">指派</div>
    <div class="btn-comm" data-toggle="modal" data-target="#delClient">删除</div>
    <div class="btn-comm btn-exp">导出全部</div>
    <button class="btn-eqs">查询</button>
    <div class="input-wap">
        <select name="cluesName" id="cluesName">
            <option value="0">企业名称</option>
            <option value="1">企业账号</option>
            <option value="2">联系人</option>
        </select>
        <input type="text" class="search-name" name="searchName" id="searchName"/>
    </div>
</div>
<div class="table-wap">
    <table>
        <tr class="list-title">
            <td class="col-sm-1"><input type="checkbox" id="allCheck"/></td>
            <td class="col-sm-1">企业名称</td>
            <td class="col-sm-1">企业账号</td>
            <td class="col-sm-1">联系人</td>
            <td class="col-sm-1">所在地区</td>
            <td class="col-sm-1">公司类型</td>
            <td class="col-sm-1">客户等级</td>
            <td class="col-sm-1">跟进状态</td>
            <td class="col-sm-1">最新跟进时间</td>
            <td class="col-sm-1">下次跟进时间</td>
            <td class="col-sm-1 last-col">负责客服</td>
        </tr>
        <?php
        foreach($enterpriseList as $value){

        ?>
        <tr class="chk">
            <td class="col-sm-1"><input type="checkbox" name="chk"/></td>
            <td class="col-sm-1"><a href="<?=Url::toRoute(['enterprises/enterprise-detail','id'=>$value['id']])?>"><?=$value['enterpriseName']?></a></td>
            <td class="col-sm-1"><?=$value['enterpriseAccount']?></td>
            <td class="col-sm-1"><?=$value['contacts']['contactName']?></td>
            <td class="col-sm-1"><?=$value['province']['name']?>-<?=$value['city']['name']?></td>
            <td class="col-sm-1"><?=$value['companyType']['typeName']?></td>
            <td class="col-sm-1"><?=$value['enterpriseGrade']['name']?></td>
            <td class="col-sm-1"><?=$value['followStatus']['name']?></td>
            <td class="col-sm-1"><?=$value['lastFollowTime']?></td>
            <td class="col-sm-1"><?=$value['nextFollowTime']?></td>
            <td class="col-sm-1 last-col"><?=$value['users']['userName']?></td>
        </tr>
        <?php
        }
        ?>

    </table>
    <p class="page-col">共<span>7</span>条，共<span>1</span>页</p>
</div>
<div class="error-kong">
    <div class="errorKong" data-toggle="modal" data-target="#addClient">
        <img src="images/unlucky.png"/>
        <p>还没有数据哦~</p>
    </div>
</div>
<!--新增表单-->
    <div class="modal" id="addClient" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title add-title">新增/编辑企业</h4>
                </div>
                <div class="modal-body">
                    <form id="enterpriseForm" action="" method="post">
                        <label class="modal-label"><span class="red">*</span>企业名称：</label>
                        <input type="text" placeholder="" name="enterpriseName" id="enterpriseName" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label"><span class="red">*</span>企业账号：</label>
                        <input type="text" placeholder="" name="enterpriseAccount" id="enterpriseAccount" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label"><span class="red">*</span>法人：</label>
                        <input type="text" placeholder="" name="legalPerson" id="legalPerson" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label"><span class="red">*</span>负责人：</label>
                        <input type="text" placeholder="" name="responName" id="responName" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label"><span class="red">*</span>公司地址：</label>
                        <select name="provinceId" id="provinceId" class="modal-select-sm">
                            <option value="0">--省份--</option>
                            <?php foreach($provinceList as $key=>$value){

                                ?>
                                <option value="<?=$value['code']?>"><?=$value['name']?></option>

                                <?php
                            }
                            ?>
                        </select>
                        <select name="cityId" id="cityId" class="modal-select-sm">
                            <option value="0">--城市--</option>
                            <?php foreach($citiesList as $key=>$value){

                                ?>
                                <option value="<?=$value['code']?>"><?=$value['name']?></option>

                                <?php
                            }
                            ?>
                        </select>
                        <input name="address" id="address" class="modal-input-lg left-input" type="text"/>
                        <div class="clear"></div>
                        <label class="modal-label"><span class="red">*</span>公司类型：</label>
                        <select name="companyType" id="companyType" class="modal-select-sm">
                            <option value="0">--请选择--</option>
                            <?php foreach($companyCatsList as $key=>$value){

                                ?>
                                <option value="<?=$value['id']?>"><?=$value['typeName']?></option>

                                <?php
                            }
                            ?>
                        </select>
                        <div class="clear"></div>
                        <label class="modal-label"><span class="red">*</span>联系人：</label>
                        <input type="text" name="contactName" id="contactName" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label"><span class="red">*</span>联系电话：</label>
                        <input type="text" placeholder="" name="phone" id="phone" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label-lo"><span class="red">*</span>身份证是否为法人/有无授权：</label>
                        <select name="idCardStatus" id="personImpower" class="modal-select-sm modal-lo">
                            <option value="0">--请选择--</option>
                            <option value="1">否/无</option>
                            <option value="2">否/有授权</option>
                            <option value="3">有/无</option>
                        </select>
                        <div class="clear"></div>
                        <label class="modal-label-lo"><span class="red">*</span>负责人是否和身份证一致：</label>
                        <select name="isSame" id="isSame" class="modal-select-sm modal-lo">
                            <option value="0">--请选择--</option>
                            <option value="1">是</option>
                            <option value="2">否</option>
                        </select>
                        <div class="clear"></div>
                        <div class="many-wap">
                            <label class="modal-label">下次跟进时间：</label>
                            <input class="span2 datetimepicker modal-input-lg" name="nextFollowTime" id="nextFollowTime" size="16" type="text" value="">
                            <div class="clear"></div>
                            <label class="modal-label">负责客服：</label>
                    <select name="departmentId" id="departmentId" class="modal-select-sm" onchange="getDepartmentList(this)">
    <option value="0">--部门--</option>
    <?php foreach($departmentList as $value){

        ?>
        <option value="<?=$value['id']?>" ><?=$value['departName']?></option>

        <?php foreach($value['twoGrade'] as $twoValue){
            ?>
            <option value="<?=$twoValue['id']?>">-<?=$twoValue['departName']?></option>
            <?php
            foreach($twoValue['threeGrade'] as $threeValue){
                ?>
                <option value="<?=$threeValue['id']?>">--<?=$threeValue['departName']?></option>
                <?php
                foreach($threeValue['fourGrade'] as $fourValue){
                    ?>
                    <option value="<?=$fourValue['id']?>">---<?=$fourValue['departName']?></option>
                    <?php
                    foreach($fourValue['fiveGrade'] as $fiveValue){

                        ?>

                        <option value="<?=$fiveValue['id']?>">----<?=$fiveValue['departName']?></option>
                    <?php } ?>
                    <?php
                } ?>
            <?php    } ?>
        <?php } ?>

    <?php } ?>
</select>
<select name="responUserId" id="responUserId" class="modal-select-sm">
    <option value="0">--员工--</option>

</select>
<script>
    function getDepartmentList(object){
        var params={};
        params.departmentId=$(object).val();
        console.log(params);
        var url="<?=Url::toRoute(['system/department-list'])?>";
        $.post(url,params,function(data){
            var data=JSON.parse(data);
            var str='';
           data.forEach(function(v){
               str+='<option value="'+v['id']+'">'+v['userName']+'</option>';
           });
            console.log(str);
            $(object).next().html(str);
        });

    }
</script>
                            <div class="clear"></div>
                            <label class="modal-label">申请时间：</label>
                            <input class="span2 datetimepicker modal-input-lg start" name="applyTime" id="applyTime" size="16" type="text" value="">
                            <div class="clear"></div>
                            <label class="modal-label">通过时间：</label>
                            <input class="span2 datetimepicker modal-input-lg end" name="passTime" id="passTime" size="16" type="text" value="">
                            <div class="clear"></div>
                            <label class="modal-label">推荐人：</label>
                            <input type="text" name="recommender" id="recommender" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">推荐人手机：</label>
                            <input type="text" name="recomCell" id="recomCell" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">注册资金(万元)：</label>
                            <input type="text" name="registerBonus" id="registerBonus" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">电话：</label>
                            <input type="text" name="enterprisePhone" id="enterprisePhone" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">传真：</label>
                            <input type="text" name="fax" id="fax" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">邮箱：</label>
                            <input type="text" name="email" id="email" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">企业网站：</label>
                            <input type="text" name="enterpriseSite" id="enterpriseSite" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">主营产品：</label>
                            <input type="text" name="mainProducts" id="mainProducts" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">产品标准：</label>
                            <input type="text" name="standardId" id="standardId" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">产能/库存(吨)：</label>
                            <input type="text" name="stock" id="stock" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">月销售量(吨)：</label>
                            <input type="text" name="monthSale" id="monthSale" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">加工情况：</label>
                            <input type="text" name="processMsg" id="processMsg" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label">主营地区：</label>
                            <input type="text" name="mainAddress" id="mainAddress" class="modal-input-lg"/>
                            <div class="clear"></div>
                            <label class="modal-label-bz">备&emsp;&emsp;注：</label>
                            <textarea name="remarks" id="remarks" cols="30" rows="10"></textarea>
                            <div class="clear"></div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn-default btn many">展开更多信息</button>
                    <button type="button" class="btn btn-primary" onclick="commitEnterprise()">保存</button>
                    <button type="button" class="btn btn-default btn-qx" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal" id="importClient" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title add-title">导入企业</h4>
                </div>
                <div class="modal-body">
                    <form action="" method="post">
                        <p class="modal-em2">1、<a href="">点击下载导入企业模板</a>将要导入的数据填充到手速局导入模板文件中。</p>
                        <p class="modal-em4">注意事项：</p>
                        <p class="modal-em4">1）模板中的表头不可更改，表头行不可删除；</p>
                        <p class="modal-em4">2）除必填的列以外，不需要的列可以删除；</p>
                        <p class="modal-em4">3）单次导入的数据不超过1000条。</p>
                        <p class="modal-em2">2、数据重复时的处理方式：<span class="bold">不导入</span></p>
                        <p class="modal-em4">查重规则：企业名称、企业账号</p>
                        <p class="modal-em2">3、选择要导入的数据文件</p>
                        <input name="importFile" type="file" class="modal-input-file"/>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary btn-sub" data-dismiss="modal">开始导入</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
<!--指派-->
<div class="modal" id="appointClient" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title add-title">指派线索</h4>
            </div>
            <div class="modal-body">
                <form action="" method="post" >
                    <label class="modal-label">新负责人：</label>
                    <select name="aresponService" class="modal-select-sm">
                        <option value="0">--部门--</option>
                        <option value="1">运营</option>
                        <option value="2">客服</option>
                    </select>
                    <select name="aserviceUser" class="modal-select-sm">
                        <option value="0">--员工--</option>
                        <option value="1">运营</option>
                        <option value="2">客服</option>
                    </select>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn-sub" data-dismiss="modal">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--删除-->
<div class="modal" id="delClient" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title add-title">提示</h4>
            </div>
            <div class="modal-body">
                <p class="modal-p">确定删除所选联系？该操作成功后，将无法恢复！</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn-del" data-dismiss="modal">确定删除</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
    <script>
        $("#addClient").modal({
            keyboard:false,
            show:false
        });
        $("#importClient").modal({
            keyboard:false,
            show:false
        });
//        指派、删除弹框js
        $("#appointClient").modal({
            keyboard:false,
            show:false
        });
        $("#delClient").modal({
            keyboard:false,
            show:false
        });

//        搜索
        $(".clues-search select").change(function () {
            var date ={};
            date.province = $("#province").val();
            date.city = $("#city").val();
            date.clueSource = $("#clueSource").val();
            date.cooperDegree = $("#cooperDegree").val();
            date.followState = $("#followState").val();
            date.unfollowTime = $("#unfollowTime").val();
            date.responService = $("#responService").val();
            date.serviceUser = $("#serviceUser").val();
            date.appointState = $("#appointState").val();
            var url ='';
            $.post(url,date, function () {
                error:{
                    layer.msg("失败");
                }
            })
        });
        $(".btn-eqs").click(function () {
            var searchs = {};
            searchs.cluesName = $("#cluesName").val();
            searchs.searchName = $("#searchName").val();
            var url = '';
            $.post(url,searchs, function () {
                error:{
                    layer.msg("失败");
                }
            })
        });
        function commitEnterprise(){
            var params=$('#enterpriseForm').serialize();
            var url="<?=Url::toRoute(['enterprises/edit-enterprised'])?>"
            $.post(url,params,function(data){
                var data=JSON.parse(data);
                if(data.errcode==0){
                    layer.msg(data.errmsg);
                    window.location.reload();
                }else{
                    layer.msg(data.errmsg);
                }
            });
        }
    </script>
</body>
</html>